/* 配置tomcat绝对路径 */
/* var tomcatPath="D:/ProgramFiles/apache-tomcat-7.0.96"; */
/* 配置emf文件绝对路径 */
/* var emfPath="XML/illustrations"; */

/* 配置多媒体文件路径 */
var emfPath=parent.parent.emfPath;
/* 配置IP */
//var baseApi="http://127.0.0.1:8080/";
var baseApi=parent.parent.IP;
var baseMappingPath = sessionStorage.getItem("mappingPath");
var PREFIX = sessionStorage.getItem("PREFIX");

//解决jq跨域
jQuery.support.cors=true;

//点击任意位置关闭导航栏弹出页和维修计划弹出页
$(document).click(function () {
	// parent.parent.$("#addBookRemarkId").css("display","none");
	// parent.parent.$("#addReadRecords").css("display","none");
	// parent.parent.$("#maintenance_plan_list").css('display','none');
	// parent.parent.$("#maintenance_plan_list").children("ul").empty();
	// parent.parent.$(".dropdown").removeClass("open");
	parent.$("#searchResultList").empty();
	parent.$("#searchResultDiv").css("display","none");
});

//判断图片变形--兼容
imgDistortion()
function imgDistortion(){
    var fileEndWith = $(".figure img").attr("src");
	if (fileEndWith != undefined && fileEndWith != null) {
		//判断是图片还是SVG
		if (fileEndWith.toLowerCase().indexOf('.svg') <= -1) {
			$(".figure img").css({"object-fit":"scale-down","background-color": "#FFFFFF00"})
		}else{
			$(".figure img").css({"background-color": "#FFFFFF"})
		}
	}
}

/* emf矢量图文件替换为绝对路径 */
$("img").each(function(){
	var url=$(this).attr("src");
	var suffix=url.substr(url.lastIndexOf("."));
	var arr = window.location.pathname.split("/");
	var parjectName=arr[arr.length-2];
	if(suffix==".emf"){
		$(this).attr("src","file:///"+emfPath+"/"+parjectName+"/illustrations/"+url.substr(url.lastIndexOf("/")));
	}
})
loadProperties();
/* xml 引用模块 临时接口后期后台完善需改*/

var y = ""
$("body").mousedown(function (e) {
	if (1 == e.which) {
		//获取左键键点击坐标
		var x = e.clientX + $(window).scrollLeft();
		y = e.clientY + $(window).scrollTop();
	}
	if(y==""||y==null||y==undefined){
		y = e.clientY + $(window).scrollTop() - 55;
	}
})

//避免变量污染，此处冗余不要删除
var clickY = ""
$("body").mousedown(function (e) {
	if (1 == e.which) {
		//获取左键键点击y坐标
		clickY = e.clientY + $(window).scrollTop();
	}
	if(clickY==""||clickY==null||clickY==undefined){
		clickY = e.clientY + $(window).scrollTop() - 55;
	}
})

var fixedY = ""
$(".tbody").mousedown(function (e) {
	if (1 == e.which) {
		//获取锁定表头的表格内div滚动条的高度
		fixedY = $(".fixed-thead-body").scrollTop();
	}
	if(fixedY==""||fixedY==null||fixedY==undefined){
		fixedY = $(".fixed-thead-body").scrollTop() - 55;
	}
	console.log("fixedY:"+fixedY);
})

function dmRefLink(path,dataId) {
	console.log(dataId);
	// 生成新的目标模块浏览页面
	var u = baseApi + PREFIX + "DateModel/showViewForDateModel";
	$.ajax({
	    type: "GET",
	    url: u,
	    data: {
			'dmRef':path,
			'showType':'view'
		},
	    dataType: "JSON",
	    success: function (res) {
	        if (res.resp_code=='0') {
				if(res.datas.length>0){
					window.parent.saveHis(baseApi + baseMappingPath + res.datas);
					location.href=baseApi + baseMappingPath + res.datas;
					if(!parent.$("#hotspot").is(":hidden")){
						parent.$("#hotspot").hide();
						parent.$("#one").show();
						parent.$("#two").show();
					}
					window.parent.saveForwardBackDate(baseApi + baseMappingPath + res.datas,clickY,dataId,fixedY);
				}
	            //window.open(baseApi + r.data.toString().substring(r.data.toString().indexOf("upload")) + "?ran=" + new Date().getTime(), 'width=1000,height=1000');
	            //window.location.href=baseApi + r.data.toString().substring(r.data.toString().indexOf("upload")) + "?ran=" + new Date().getTime();
	        } else {
	            layer.msg(i18n("i18n-alert-noDatemodel"))
	        }
	    },
	    error: function (res) {

	    }
	});

}

/* cll 初始化xsl自定义的常量 */
if(PREFIX != 'gjb' ){
	// initXslFloat();
}
//xtt修改cll方法
function initXslFloat(){
	var url = baseApi + "padBrex/getPadBrexByRef";
	var dmRef = $(".brex").html();
	$.ajax({
		type:"GET",
		url:url,
		data:{
			"dmRef":dmRef
		},
		dataType:"JSON",
		success: function(res){
			if(res.resp_code=='0'){
				if(res.datas.length>0){

					var brex=JSON.parse(res.datas[0].structureObjectRules);
					var thresholdUnitOfMeasures;
					//获取所有的@ThresholdUnitOfMeasure值
					for(var i=0;i<brex.length;i++){
						if(brex[i].objectPath == "//threshold/@thresholdUnitOfMeasure"){
							thresholdUnitOfMeasures = brex[i].objectKeyValue;
						}
					}

					//循环遍历ThresholdUnitOfMeasure值
					if(thresholdUnitOfMeasures){
						$(".thresholdUnitOfMeasure").each(function(){
							var thresholdUnitOfMeasure = $(this).text();
							for(var key in thresholdUnitOfMeasures){
								if(key == thresholdUnitOfMeasure){
									$(this).html(thresholdUnitOfMeasures[key]);
								}
							}
						})
					}

				}
			}
		},error: function(res){

		}
	})
}

/* cll 描述类编号 描述类手动添加段落序号 */
//number()
function number(){
	$(".levelledPara").each(function(){
		if($(this).children(".numberPara").length>0){
			return true;
		}
		var siblings = $(this).parent().children(".levelledPara");
		siblings.each(function(index,element){
			if($(this).parents(".levelledPara").length>0){
				var num = $(this).parent(".levelledPara").children(".numberPara").attr("num");
				$(this).prepend("<span class=\"numberPara\" num=\""+num+"."+(index+1)+"\">"+num+"."+(index+1)+"&nbsp;"+"</span>");
			}else{
				$(this).prepend("<span class=\"numberPara\" num=\""+(index+1)+"\">"+(index+1)+"&nbsp;"+"</span>");
			}
		})
	})
}

/* cll 处理全屏显示multimedia 热区 */
/* image */
$(".graphic").on("click",function() {
	var _this = $(this);//将当前的pimg元素作为_this传入函数
	var url = window.location.href;
	var projectPath=url.substring(0,url.lastIndexOf("/"));

	var hot = [];
	var hotArr = $(this).parent().find(".hotspot");
	hotArr.each(function(index,element){
		if($(element).attr("visibility")=="visible"){
			hot.push({"id":$(element).attr("id"),"hotspottitle":$(element).attr("hotspottitle"),"objectdescr":$(element).attr("objectdescr")});
		}
	})
	//ie8 兼容模式
	var fileEndWith = _this.attr("src");
	if(fileEndWith.toLowerCase().indexOf('.svg')>-1){
		//alert("svg");
		var hotId = _this.attr('id');
		//console.log(hotId)
		parent.openSVG(projectPath + "/" + _this.attr("src"),hotId);
	}else{
		if(_this.attr("src").indexOf(projectPath)<0){
			//parent.parent.imgShow("#outerdiv", "#innerdiv", "#bigimg", projectPath+"/"+_this.attr("src"));
			var image = new Image();
			image.src = projectPath + "/" + _this.attr("src");
			image.onload = function(){
				// 显示尺寸
				parent.hotImgShow(projectPath+"/"+_this.attr("src"),hot,_this);
			}

		}else{
			//parent.parent.imgShow("#outerdiv", "#innerdiv", "#bigimg", _this.attr("src"));
			var image = new Image();
			image.src = _this.attr("src");
			image.onload = function(){
				// 显示尺寸
				parent.hotImgShow(_this.attr("src"),hot,_this);
			}
		}
	}

});

/* cll 处理图片热区点击文字 */
// $(".internalRef").on("click",function(){
$("body").on('click','.internalRef',function(){
	var _this=$(this);
	var id = $(this).attr("href").substr(1);

	var src = $("#" + id).parent().children("img").attr("src");
	//console.log(src)
	if(src != null){
		// alert(src.toLowerCase());
		if(src.toLowerCase().indexOf('.svg')>-1){

			var url = window.location.href;
			var projectPath=url.substring(0,url.lastIndexOf("/"));

			//var hotId = $("#" + id).parent().children("img").parent().parent().attr('id') + "-" + $("#" + id).parent().children("img").attr('id');
			var hotId = $("#" + id).parent().children("img").attr('id');
			//console.log(hotId);

			//xtt增加svg多热点
			// if($("#" + id).attr("objectdescr")!=""){
			// 	id = $("#" + id).attr("objectdescr");
			// }

			window.parent.openSVGbyhotText(projectPath + "/" + src,id,hotId);
			$(".internalRef").css({"background-color":"none","color":"#337ab7"});
			_this.css({"background-color":"#FF6666","color":"#FFFFFF"});
		}else{
			$(".figure .hotspot").each(function(){
				if($(this).attr("id")==id){
					if(window.parent.document.getElementById('hotspot').style.display == "none"){
						var hot = [];
						var hotArr = $(this).siblings(".graphic").parent().find(".hotspot");
						hotArr.each(function(index,element){
							if($(element).attr("visibility")=="visible"){
								hot.push({"id":$(element).attr("id"),"hotspottitle":$(element).attr("hotspottitle"),"objectdescr":$(element).attr("objectdescr")});
							}
						})
						var url = window.location.href;
						var projectPath=url.substring(0,url.lastIndexOf("/"));
						parent.hotImgShow(projectPath + "/" + $(this).siblings(".graphic").attr("src"),hot,$(this).siblings(".graphic"));
						parent.showHot(id);
						$(".internalRef").css({"background-color":"none","color":"#337ab7"});
						_this.css({"background-color":"#FF6666","color":"#FFFFFF"});
					}else{
						parent.showHot(id);
						$(".internalRef").css({"background-color":"none","color":"#337ab7"});
						_this.css({"background-color":"#FF6666","color":"#FFFFFF"});
					}
				}
			})
		}
	}

})

/* cll 处理图片热区点击图片中的热区 */
function showHotRef(id){
	var top=0;
	$(".internalRef").css({"background-color":"none","color":"#337ab7"});
	$(".internalRef").each(function(){
		var idRef = $(this).attr("href").substr(1);
		if(id==idRef){
			$(this).css({"background-color":"#FF6666","color":"#FFFFFF"});
			if(top==0){
				top=$(this).offset().top;
				$(document).scrollTop(top);
			}
		}
	})
}

/* cll 关闭图片热区 */
function closeHot(){
	$(".internalRef").css({"background-color":"none","color":"#337ab7"});
}

/* video,audio */
$(".multimedia_preview").on("click",function(){
	var multimedia=$(this).parent(".multimediaObject").attr("url");
	var url = window.location.href;
	var projectPath=url.substring(0,url.lastIndexOf("/"));
	//ie8 兼容模式
	if(multimedia.indexOf(projectPath)<0){
		parent.parent.multimediaShow(projectPath+"/"+multimedia);
	}else{
		parent.parent.multimediaShow(multimedia);
	}
});

/* 将InfoName 传给父页面作为标题显示*/
$(function(){

	/* 处理准备工作 准备工作中值会有多项，中间用边框间隔 */
	$(".preliminaryRqmts table tr").find("td:last-child").children("div").css({"padding":" 10px 0","border-top":" 1px solid #E6E1E1"});
	$(".preliminaryRqmts table tr").find("td:last-child").children("div:first-child").css({"border-top":" none"});


	// parent.addDmTitle($(".lbody-title>p").html());
	//获取数据模块名称（InfoName 信息名）
	sessionStorage.setItem("messageDmcTitle",$(".lbody-title>p").html());
	//获取数据模块编码
	var arr = window.location.pathname.split("/");
	var urlFilename = arr[arr.length-1].substring(0,arr[arr.length-1].lastIndexOf("."));
	var dmc = urlFilename.substring(0,urlFilename.indexOf("_"));
	sessionStorage.setItem("messageDmc",dmc);

	//输入框框
	$(".para").each(function(){
		if($(this).text().indexOf("__________") > -1){
			var html = $(this).html();
			html = html.replaceAll('__________', '<span contenteditable="true" class="write"></span>');
			$(this).html(html);
		}
	})

})

/* 滚动条位置 */
//获取滚动条位置
function getScrollTop(){
	return $(document).scrollTop();
}
//设置滚动条位置
function setScrollTop(height){
	$(document).scrollTop(height);
}

//点击svg部位高亮显示文本
function showSVGHotRef(imgId,svgId){
	id = imgId + svgId;
	id_hot = imgId + "hot-" + svgId;
	var top=0;
	$(".internalRef").css({"background-color":"none","color":"#337ab7"});
	var refId;
	$(".hotspot").each(function(){
		var idRefs = $(this).attr("objectdescr");
		//console.log(idRef);
		if(idRefs.indexOf(id) > -1){
			refId = $(this).attr("id");
			//console.log(refId)
		}
	})

	$(".internalRef").each(function(){
		var idRef = $(this).attr("href").substr(1);
		//console.log(idRef);
		if(id==idRef || idRef==refId || idRef==id_hot){
			$(this).css({"background-color":"#FF6666","color":"#FFFFFF"});
			if(top==0){
				top=$(this).offset().top;
				$(document).scrollTop(top);
			}
		}
	})

}

//xtt警告注意弹窗
alertWarning();
function alertWarning(){
	var warnings = document.getElementsByClassName("warning");
	var cautions = document.getElementsByClassName("caution");
	if(warnings.length > 0 || cautions.length > 0){
		//console.log(warnings);
		window.parent.alertWarning(warnings,cautions);
	}
}

//表格图片列表功能
function addList(obj){
	//表格
	if(obj.attr("class") == "table"){
		// $("#DmMedialist").append('<li class="layui-timeline-item dmMediaLi-table"><i class="layui-icon layui-timeline-axis circle"></i><a class="layui-timeline-title dmMediaLi-table-a" >'  + obj.find(".table-head").text() + '</a></li>');
	}else if(obj.attr("class") == "figure"){
		// $("#DmMedialist").append('<li class="layui-timeline-item dmMediaLi-figure"><i class="layui-icon layui-timeline-axis circle"></i><a class="layui-timeline-title dmMediaLi-figure-a">'  + obj.find(".figure-title").text() + '</a></li>');
	}
	// else if(obj.attr("class") == "content-title" ){
	else if(obj.attr("class") == "content-title" && obj.parent().attr("class") == "para0"){
		$("#DmMedialist").append('<li class="layui-timeline-item dmMediaLi-title"><i class="layui-icon layui-timeline-axis circle"></i><a class="layui-timeline-title dmMediaLi-title-a" >'  + obj.text() + '</a></li>');
	}
}

function addListShow() {
	if($("#DmMedialist").children().length > 0){
		$("#DmMedialistDiv").css({"width":"10%","display":"inline-block"});
		$(".lbody").css({"width":"89%","display":"inline-block","margin-left":"10%"});
	}else{
		$("#DmMedialistDiv").css({"width":"0%","display":"none"});
	}
}

//导航标题点击定位到文字
function getTitlePosition(str){
	$(".headline_btitle,.title").each(function(){
		if($(this).text().indexOf(str) > -1){
			var title_top = $(this).offset().top;
			$(document).scrollTop(title_top);
		}
	})
}

//导航标题点击定位到表格
function getTablePosition(str){
	str = str.replace(i18n("i18n-lan-table")+"--","");
	$(".table-head").each(function(){
		if($(this).text() == str){
			var table_top = $(this).offset().top;
			$(document).scrollTop(table_top);
		}
	})
}

//导航标题点击定位到图
function getFigurePosition(str){
	str = str.replace(i18n("i18n-lan-figure")+"--","");
	$(".figure-title").each(function(){
		if($(this).text() == str){
			var figure_top = $(this).offset().top;
			$(document).scrollTop(figure_top);
		}
	})
}

//显示更改标记
function showUpdateLog(){
	$(".delete").addClass("showDelete");
	$(".add").addClass("showAdd");
	$(".modify").addClass("showModify");
}

//隐藏更改标记
function hideUpdateLog(){
	$(".delete").removeClass("showDelete");
	$(".add").removeClass("showAdd");
	$(".modify").removeClass("showModify");
}

$(".externalPubRefIdent").on("click",function() {
	//alert("hh")
	var href = $(this).attr("tohref");
	//console.log("aaa")
	window.open(href);
});
